# -*- coding:utf-8 -*-
# @Time : 21-7-22 下午5:04 
# @Author : zdy
# @File : Program.py
# desc:
import os
import shelve
import sys
import glob
from importQT import *
from Class.Log import log
from Class.Devices import *
if deviceType == "CS":
    from UIClass.main import UIMain
else:
    from UIClass.mainONH import UIMain
from UIClass.UILogin import UILogin

if __name__ == '__main__':
    dirname = os.path.dirname(PyQt5.__file__)
    plugin_path = os.path.join(dirname, "Qt", 'plugins')
    os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
    inPutPath = os.path.dirname(os.path.realpath(sys.argv[0]))  # 程序运行的绝对路径
    log.setConfig(os.path.join(inPutPath, "log.conf"))
    log.info("程序", "开始")
    app = QtWidgets.QApplication(sys.argv)
    # 输出界面主题样式
    # print(QtWidgets.QStyleFactory.keys())
    app.setStyle(QtWidgets.QStyleFactory.create("fusion"))  # "windows""fusion""windowsxp"
    #<editor-fold desc="调用PYQT5自带的翻译文件">
    translator = QTranslator(app)
    if translator.load(os.path.join(inPutPath, "qt_zh_CN.qm")):
        app.installTranslator(translator)
    #</editor-fold>
    #<editor-fold desc="登陆">
   # pyqtgraph.examples.run()
    # login = UILogin(inPutPath)
    # if login.exec() == 1:
        #</editor-fold>
    if device.init(inPutPath):
        w = UIMain()
        w.setWindowModality(QtCore.Qt.WindowModal)
        w.show()
        app.exec()
        device.deinit()
    else:
        QtWidgets.QMessageBox.critical(None, "提示", "数据文件丢失！")
    # 删除文件夹下的temp文件
    for file in glob.glob(os.path.join(inPutPath,"temp*.pdf")):
        os.remove(file)
    log.info("程序", "退出")
    sys.exit(0)
